<template>
    <div>
              <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
    </el-breadcrumb>
       <!-- 卡片视图 -->
    <el-card>
      <el-row :gutter="20">
        <el-col :span="10">
          <!-- 搜索框 -->
          <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getGoodsList()">
            <el-button slot="append" icon="el-icon-search" @click="getGoodsList()"></el-button>
          </el-input>
        </el-col>
        <el-col :span="4"><el-button type="primary" @click="addGoods">添加用户</el-button></el-col>
      </el-row>
      <!-- 用户列表区域 -->
      <el-table :data="goodslist" style="width: 100%" border stripe>
      <el-table-column type="index" label="#"></el-table-column>
      <el-table-column prop="account" label="账号"></el-table-column>
      <el-table-column prop="name"  label="名称"></el-table-column>
      <el-table-column prop="email" label="邮箱"> </el-table-column>
      <!-- <el-table-column prop="goods_weight" label="商品重量"> </el-table-column>
      <el-table-column prop="add_time" label="创建时间">
          <template slot-scope="scope">
              {{scope.row.add_time |dateFormat}}
          </template>
      </el-table-column> -->
      <el-table-column label="操作">
        <template slot-scope="scope">
          <!-- 修改按钮 -->
        <el-button type="primary" icon="el-icon-edit" circle size="small" @click="showEditDialog(scope.row.id)"></el-button>
        <!--删除按钮  -->
        <el-button type="danger" icon="el-icon-delete" circle size="small" @click="removeUserById(scope.row.id)"></el-button>
      </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination @size-change="handleSizeChange"  @current-change="handleCurrentChange"  :current-page="queryInfo.pagenum"
     :page-sizes="[10, 15, 30, 50]"  :page-size="queryInfo.pagesize"  layout="total, sizes, prev, pager, next, jumper" :total="total" background>
    </el-pagination>
    </el-card>
    </div>
</template>
<script>
export default {
  data () {
    return {
      queryInfo: {
        //   查询搜索参数
        query: '',
        // 当前显示多少条默认
        pagesize: 10,
        // 当前页码值，默认第一页
        pagenum: 1
      },
      goodslist: [],
      total: 0
    }
  },
  created () {
    this.getGoodsList()
  },
  methods: {
    //   根据分页获取对应的商品列表
    async getGoodsList () {
      const { data: res } = await this.$http.get('http://localhost:8080/user/list', { params: this.queryInfo })
      console.log(res)
      if (res.code !== 200) {
        return this.$message.error('获取商品信息失败')
      }
      this.goodslist = res.data
      console.log(this.goodslist)
      this.total = this.goodslist.length
    },
    handleSizeChange (newsize) {
      this.queryInfo.pagesize = newsize
      this.getGoodsList()
    },
    // 监听页码值改变的事件
    handleCurrentChange (newPage) {
      this.queryInfo.pagenum = newPage
      this.getGoodsList()
    },
    addGoods () {
      this.$router.push('/goods/add')
    },
    showEditDialog (id){
      console.log('edit dialog id-->' + id);
    }
  }
}
</script>
<style lang="less" scoped>

</style>
